/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <cstring>
using namespace std;
struct res
{
    char id[17];
    int deskId;
} info[1001];
int main_1041()
{
    int N,M,n,l;
    char m[17]={0};
    scanf("%d",&N);
    for (int i=0;i<N ;++i )
    {
        scanf("%s %d %d",m,&n,&l);
        strcpy(info[n].id,m);
        info[n].deskId=l;
    }
    scanf("%d",&M);
    for (int i=0;i<M ;++i )
    {
        scanf("%d",&n);
        printf("%s %d\n",info[n].id,info[n].deskId);
    }
	return 0;
}
